//
//  LYIncomBreakDownCell.m
//  SelectCity
//
//  Created by liuyan on 2019/3/30.
//  Copyright © 2019年 liuyan. All rights reserved.
//

#import "LYIncomBreakDownCell.h"

@interface LYIncomBreakDownCell()

@property (nonatomic, strong) UILabel *priceLabel;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *timeLabel;

@end

@implementation LYIncomBreakDownCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initSubViews];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

#pragma mark - InitSubViews
- (void)initSubViews{
    self.priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH -70, 0, 60, 50)];
    self.priceLabel.font = [UIFont systemFontOfSize:14];
    self.priceLabel.textColor = [UIColor redColor];
    self.priceLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:self.priceLabel];
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5, self.priceLabel.left - 20, 20)];
    self.titleLabel.font = [UIFont systemFontOfSize:14];
    self.titleLabel.textColor = RGB(34, 34, 34);
    [self.contentView addSubview:self.titleLabel];
    
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLabel.left, self.titleLabel.bottom, self.titleLabel.width, 19)];
    self.timeLabel.font = [UIFont systemFontOfSize:12];
    self.timeLabel.textColor = RGB(153, 153, 153);
    [self.contentView addSubview:self.timeLabel];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(20, 49, WIDTH - 40, 1)];
    line.backgroundColor = RGB(247, 247, 247);
    [self.contentView addSubview:line];
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _titleLabel.text = dataDic[@"title"];
    _timeLabel.text = [UIToolsControl conversionMonthDayHoursMinuteOrHoursMinute:[dataDic[@"add_time"] integerValue]];
    if ([dataDic[@"typeid"] integerValue] == 1) {
        _priceLabel.text = [NSString stringWithFormat:@"+%li",[dataDic[@"coins"] integerValue]];
         _priceLabel.textColor = [UIColor greenColor];
    }else{
        _priceLabel.text = [NSString stringWithFormat:@"-%li",[dataDic[@"coins"] integerValue]];
         _priceLabel.textColor = [UIColor redColor];
    }
}

-(void)setExpendDic:(NSDictionary *)expendDic{
    _titleLabel.text = expendDic[@"title"];
    _timeLabel.text = [UIToolsControl conversionMonthDayHoursMinuteOrHoursMinute:[expendDic[@"add_time"] integerValue]];
    if ([expendDic[@"typeid"] integerValue] == 1) {
        //收入
        _priceLabel.text = [NSString stringWithFormat:@"+%.2f",[expendDic[@"amount"] floatValue]];
        _priceLabel.textColor = [UIColor greenColor];
    }else{
        //支付
        _priceLabel.text = [NSString stringWithFormat:@"-%.2f",[expendDic[@"amount"] floatValue]];
        _priceLabel.textColor = [UIColor redColor];
    }
    
    NSString *str = _priceLabel.text;
    if ([[str substringFromIndex:str.length-2] isEqualToString:@"00"]) {
        str = [str substringToIndex:str.length-3];
         _priceLabel.text = str;
    }else if ([[str substringFromIndex:str.length-1] isEqualToString:@"0"]){
        _priceLabel.text = [str substringToIndex:str.length-1];
    }
}

@end
